package com.spring.config;
import com.spring.interceptor.TokenInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

//通过实现WebMvcConfigurer接口并覆盖addInterceptors方法，将自定义的TokenInterceptor拦截器注册到Spring MVC的拦截器链中，使其能够拦截所有请求路径。
//        配置类使用@Configuration注解，表明这是一个配置类，Spring会在应用启动时自动扫描并加载该配置。
@Configuration

public class TokenConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册TokenInterceptor拦截器
        InterceptorRegistration registration = registry.addInterceptor(new TokenInterceptor());
        registration.addPathPatterns("/**");                      //所有路径都被拦截
    }
}
